﻿Imports System.Xml

Public Class menuLeft
    Inherits System.Web.UI.UserControl

    Public objFunction As New FunctionClass
    Public objConfig As New Configs
    Public objAlert As New AlertClass

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Try
            Dim strHTML As New StringBuilder()
            Dim strHTML1 As New StringBuilder()
            Dim xml As String = ""
            Dim cnt As Integer = 0
            Dim cnt1 As Integer = 0
            xml = objFunction.ReadEndFile(Server.MapPath("/") & "static/outSite/listfiles/listCategory.xml")
            Dim rgx As New Regex("\n|\t|\r")
            xml = rgx.Replace(xml, "")
            Dim doc As New XmlDocument()
            doc.LoadXml(xml)
            Dim nodeList As XmlNodeList = doc.GetElementsByTagName("cat")
            For Each n As XmlNode In nodeList
                Dim id As String = n.SelectSingleNode("id").InnerText
                Dim name As String = n.SelectSingleNode("name").InnerText
                Dim type As String = n.SelectSingleNode("type").InnerText
                Dim uri As String = n.SelectSingleNode("uri").InnerText
                Dim level As String = n.SelectSingleNode("level").InnerText

                Dim perURI As String = ""

                If Integer.Parse(type) = 0 Then
                    perURI = "ProductList.aspx"
                    If Integer.Parse(level) = 1 Then
                        ' Chi phan tu dau tien moi k co the dong' UL
                        If cnt > 0 Then
                            strHTML.AppendLine("        </ul>")
                            strHTML.AppendLine("    </dd>")
                            strHTML.AppendLine("</dl>")
                        End If
                        If cnt = 0 Then
                            strHTML.AppendLine("<span class=""headerMenuLeft"">Danh mục sản phẩm</span>")
                            strHTML.AppendLine("<dl class=""dropdown"" style=""padding-top: 30px;"">")
                            strHTML.AppendLine("    <dt id=""" & cnt & "-ddheader"" class=""upperdd"" onmouseover=""ddMenu('" & cnt & "',1)"" onmouseout=""ddMenu('" & cnt & "',-1)""><a class=""menu1"">" & name & "</a></dt>")
                            strHTML.AppendLine("    <dd id=""" & cnt & "-ddcontent"" onmouseover=""cancelHide('" & cnt & "')"" onmouseout=""ddMenu('" & cnt & "',-1)"">")
                            strHTML.AppendLine("        <ul>")
                        Else
                            strHTML.AppendLine("<dl class=""dropdown"">")
                            strHTML.AppendLine("    <dt id=""" & cnt & "-ddheader"" class=""upperdd"" onmouseover=""ddMenu('" & cnt & "',1)"" onmouseout=""ddMenu('" & cnt & "',-1)""><a class=""menu1"">" & name & "</a></dt>")
                            strHTML.AppendLine("    <dd id=""" & cnt & "-ddcontent"" onmouseover=""cancelHide('" & cnt & "')"" onmouseout=""ddMenu('" & cnt & "',-1)"">")
                            strHTML.AppendLine("        <ul>")
                        End If
                    Else
                        strHTML.AppendLine("            <li><a href=""/" & perURI & "?cate=" & id & """>" & name & "</a></li>")
                    End If
                    cnt = cnt + 1
                Else
                    perURI = "NewList.aspx"
                    If Integer.Parse(level) = 1 Then
                        ' Chi phan tu dau tien moi k co the dong' UL
                        If cnt1 > 0 Then
                            strHTML1.AppendLine("        </ul>")
                            strHTML1.AppendLine("    </dd>")
                            strHTML1.AppendLine("</dl>")
                        End If
                        If cnt1 = 0 Then
                            strHTML1.AppendLine("<span class=""headerMenuLeft"">Danh mục tin tức</span>")
                            strHTML1.AppendLine("<dl class=""dropdown"" style=""padding-top: 30px;"">")
                            strHTML1.AppendLine("    <dt id=""" & cnt & "-ddheader"" class=""upperdd"" onmouseover=""ddMenu('" & cnt & "',1)"" onmouseout=""ddMenu('" & cnt & "',-1)""><a class=""menu1"">" & name & "</a></dt>")
                            strHTML1.AppendLine("    <dd id=""" & cnt & "-ddcontent"" onmouseover=""cancelHide('" & cnt & "')"" onmouseout=""ddMenu('" & cnt & "',-1)"">")
                            strHTML1.AppendLine("        <ul>")
                        Else
                            strHTML1.AppendLine("<dl class=""dropdown"">")
                            strHTML1.AppendLine("    <dt id=""" & cnt & "-ddheader"" class=""upperdd"" onmouseover=""ddMenu('" & cnt & "',1)"" onmouseout=""ddMenu('" & cnt & "',-1)""><a class=""menu1"">" & name & "</a></dt>")
                            strHTML1.AppendLine("    <dd id=""" & cnt & "-ddcontent"" onmouseover=""cancelHide('" & cnt & "')"" onmouseout=""ddMenu('" & cnt & "',-1)"">")
                            strHTML1.AppendLine("        <ul>")
                        End If
                    Else
                        strHTML1.AppendLine("            <li><a href=""/" & perURI & "?cate=" & id & """>" & name & "</a></li>")
                    End If
                    cnt = cnt + 1
                    cnt1 = cnt1 + 1

                End If
            Next
            strHTML.AppendLine("        </ul>")
            strHTML.AppendLine("    </dd>")
            strHTML.AppendLine("</dl>")

            menuLeft.InnerHtml = strHTML.ToString()
            menuLeft1.InnerHtml = strHTML1.ToString()

            strHTML = Nothing
            strHTML1 = Nothing
            doc = Nothing
            nodeList = Nothing
        Catch ex As Exception
            If objConfig.Developer.Equals("1") Then
                objAlert.ErrorBox(Page, "File: " & (New System.Diagnostics.StackTrace).GetFrame(0).GetMethod.DeclaringType.Name & _
                                  " --- Function: " & (New System.Diagnostics.StackTrace).GetFrame(0).GetMethod.Name & _
                                  " --- Mess: " & ex.Message.Replace("'", """"))
            Else
                objAlert.ErrorBox(Page, "Lỗi kỹ thuật, hãy thông báo lại với Admin, xin cảm ơn.")
            End If
        End Try
    End Sub

End Class